//
//  HggProductTableViewCell.m
//  全选和单选
//
//  Created by 胡高广 on 2017/9/18.
//  Copyright © 2017年 jinshuaier. All rights reserved.
//

#import "Zz_ContactListCell.h"//
#import "UILabel+MyLable.h"

//RGB的颜色转换
#define kUIColorFromRGB(rgbValue) [UIColor \
colorWithRed:((float)((rgbValue & 0xFF0000) >> 16))/255.0 \
green:((float)((rgbValue & 0xFF00) >> 8))/255.0 \
blue:((float)(rgbValue & 0xFF))/255.0 alpha:1.0]

#define WIDTH ([UIScreen  mainScreen].bounds.size.width)
#define HEIGHT ([UIScreen mainScreen].bounds.size.height)

@interface Zz_ContactListCell ()

//选中按钮
@property (nonatomic,retain) UIButton *selectBtn;

@end

@implementation Zz_ContactListCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self ) {
        self.backgroundColor = kUIColorFromRGB(0xffffff);
        [self createView];

    }
    return self;
}

- (void)createView {
    self.nameLabel = [[UILabel alloc]init];
    [self.contentView addSubview:self.nameLabel];


    [self.nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(10);
        make.height.mas_equalTo(44);
        make.width.mas_equalTo(100);

    }];

    /// 2.手机号码
    self.mobileLabel = [[UILabel alloc]init];
    [self.contentView addSubview:self.mobileLabel];


    [self.mobileLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.nameLabel.mas_right).mas_offset(20);
        make.height.mas_equalTo(44);
        make.right.mas_equalTo(-40);
    }];

    
    //选中按钮
    self.selectBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    self.selectBtn.frame = CGRectMake(WIDTH - 35, 15, 20, 20);
    self.selectBtn.selected = self.isSelected;
    [self.selectBtn setImage:[UIImage imageNamed:@"cart_unSelect_btn"] forState:UIControlStateNormal];
    [self.selectBtn setImage:[UIImage imageNamed:@"cart_selected_btn"] forState:UIControlStateSelected];

    [self.contentView addSubview:self.selectBtn];




    _bigSelectBtn = [UIButton buttonWithType:UIButtonTypeSystem];
    _bigSelectBtn.frame = CGRectMake(0, 0, WIDTH , 50);
    _bigSelectBtn.backgroundColor = [UIColor clearColor];
    [_bigSelectBtn addTarget:self action:@selector(selectBtnClick:) forControlEvents:UIControlEventTouchUpInside];

    [self.contentView addSubview:_bigSelectBtn];

    _lineLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 49.5, WIDTH, 0.5)];
    _lineLabel.backgroundColor = kUIColorFromRGB(0xf0f0f0);
    [self.contentView addSubview:_lineLabel];

}
-(void)setListPhoneDetailModel:(SD_ContactListPhoneDetail *)ListPhoneDetailModel{

    _ListPhoneDetailModel=ListPhoneDetailModel;

    self.mobileLabel.text=ListPhoneDetailModel.MobileCode;
    if ([[ListPhoneDetailModel.Name sy_trim] length] > 0) {
        self.nameLabel.text = ListPhoneDetailModel.Name;
    }
    else {
        self.nameLabel.font = [UIFont italicSystemFontOfSize: self.nameLabel.font.pointSize];
        self.nameLabel.text = @"无名氏";
    }

    self.selectBtn.selected = self.isSelected;

}


//选中按钮点击事件
-(void)selectBtnClick:(UIButton*)button
{
    self.selectBtn.selected = !self.selectBtn.selected;
    if (self.cartBlock) {
        self.cartBlock(self.selectBtn.selected);
    }

}

 
+(instancetype)cellForTableView:(UITableView *)tableView{
    
     
    static NSString *identifier = @"hggCellZz_ContactListCell";
    Zz_ContactListCell *hggCell  = [tableView dequeueReusableCellWithIdentifier:identifier];
    if (hggCell == nil) {
        hggCell = [[Zz_ContactListCell alloc] initWithStyle:(UITableViewCellStyleDefault) reuseIdentifier:identifier];
    }
    
    
    return hggCell;
    
}
@end
